package util.wcl
{
	import flash.display.Sprite;
	import flash.events.KeyboardEvent;
	
	import mx.controls.Alert;
	import mx.effects.Parallel;
	import mx.effects.Sequence;
	import mx.effects.Zoom;
	import mx.events.CloseEvent;
	import mx.managers.PopUpManager;

	public class AlertHelper
	{
		private static var newAlert:Alert;
		private static var handler:Function;
		public static var closeTime:Date = null;
		public static function showMessage(msg:String, title:String = "확인", parent:Sprite=null, closeHandler:Function=null):void
		{
			handler = closeHandler;
			newAlert = Alert.show(msg, title, Alert.OK, parent, myCloseHandler, null, Alert.OK); 
			newAlert.width = 300;
			newAlert.height = 120;
			newAlert.setFocus();
			newAlert.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
		}
		
		private static function onKeyDown(e:KeyboardEvent):void
		{
			trace("alert.key: " + e.target);
			if(e.keyCode == 13) {
				AlertHelper.closeTime = new Date();
				if(handler!=null) handler(new CloseEvent(CloseEvent.CLOSE));
				PopUpManager.removePopUp(newAlert);
			}
		}
		
		private static function myCloseHandler(e:CloseEvent):void
		{
			AlertHelper.closeTime = new Date();
			if(handler!=null) {
				handler(e);
			}
		}
		/**
         * Alert.show 재 정의
         */
		public static function showMsgYesNo( msg:String, title:String, parent:Sprite, yesFunction:Function, noFunction:Function, 
											 Yeslabel:String = "YES", Nolabel:String = "NO"): void
        {
        	var iconImage :Class = null;
        	var tmpTitle :String = "확인";
			
			if (title == "") title = tmpTitle ;
			Alert.yesLabel = Yeslabel;
			Alert.noLabel = Nolabel;
			
            var newAlert:Alert = Alert.show(msg, title, Alert.YES|Alert.NO, parent,
					                function(event:CloseEvent): void {
					                    if (event.detail == Alert.YES) {
					                        if (yesFunction != null) yesFunction();
					                    } else {
					                        if (noFunction != null) noFunction();
					                    }
					                },iconImage, Alert.NO
					            );
			newAlert.setFocus();
			newAlert.width = 300;
			newAlert.height = 120;		            
        }
		
		public static function setEffect():void
		{
			var sequence:Sequence = new Sequence();
			var parallel:Parallel = new Parallel();
			parallel.addChild(new Zoom());
		}
	}
}